<?php
/**
 * Created by PhpStorm.
 * User: clb
 * Date: 2019/1/22
 * Time: 16:39
 */

namespace app\response;

/**
 * 响应类
 *
 * Class Response
 */
class Response
{

    private static $instance;

    /**
     * 实例响应类
     *
     * @return Response
     */
    public static function instance()
    {
        self::$instance = new self();
        return self::$instance;
    }

    /**
     * 接口转json
     *
     * @param string $msg
     * @param array $data
     * @return string
     */
    public function error(string $msg = 'error', array $data = [])
    {
        return json_encode(
            [
                'status' => 0,
                'data' => $data,
                'msg' => $msg
            ]
        );
    }

    /**
     * 接口转json
     *
     * @param array $data
     * @param string $msg
     * @return string
     */
    public function success(string $msg = 'success', array $data = [])
    {
        return json_encode(
            [
                'status' => 1,
                'data' => $data,
                'msg' => $msg
            ]
        );
    }

}